// 所有Node.js API都可以在预加载过程中使用。
// 它拥有与Chrome扩展一样的沙盒。
import { contextBridge, ipcRenderer } from 'electron';

const invokeHandle = async (channel: string, ...args: any[]): Promise<any> => {
  const res = await ipcRenderer.invoke(channel, ...args);
  console.log(res)
  return res;
}

contextBridge.exposeInMainWorld('vAPI', {
  invokeHandle,
})

window.addEventListener("DOMContentLoaded", () => {
  const replaceText = (selector: string, text: string) => {
    const element = document.getElementById(selector);
    if (element) element.innerText = text;
  };
  const versions = ["chrome", "node", "electron"]
  for (const dependency of versions) {
    // @ts-ignore
    replaceText(`${dependency}-version`, process.versions[dependency]);
  }
});

